CS 5010: Problem Set 11
Out: Monday, November 28, 2016
Due: Monday, December 5, 2016
at 600pm local time.
The goal of this problem set is to give you experience with
inheritance and the model-viewer-controller architecture.
For this problem, you must use state and the MVC architecture, as
in Lesson 11.3 and the Examples. Use inheritance whenever
useful to minimize repeated code.
Otherwise, the deliverables and instructions for this problem set
are the same as for Problem Sets 09-10. As always, you must follow
the design recipe, in this case the OO Design Recipe and deliverables
as spelled out in Lesson 9.5 and in deliverables.html. Be sure to sync your work and fill out a Work
Session Report at the end of every work session. Use the
Work Session Report for PS
11.
Also, as with problem set 10, you may submit your solution
in multiple files.
Your task is to simulate a dimensionless particle bouncing in a
150x100 rectangle. For this system, you will produce 5
viewer-controllers:
- A position controller, similar to the one in the Examples, but
using the arrow keys to move the particle in the x or y direction.
- A velocity controller, similar to the one in the Examples, but
using the arrow keys to alter the velocity of the particle in the x
or y direction.
- Both the position and velocity controllers display both the
position and velocity of the particle, as in the demo.
- An XY controller, which shows a representation of the particle
bouncing in the rectangle. With this controller, the user can drag
the particle using the mouse. Dragging the mouse causes the
particle to follow the mouse pointer via a Smooth Drag.
- An X controller, which is like the XY controller, except that it
displays only the x coordinate of the particle's motion. Dragging
the mouse in the X controller alters the particle's position in the
x direction.
- A Y controller, which is like the X controller except that it
works in the y direction.
Here's a demonstration:
Note that the first time I hit button-down inside the canvas of
the XY controller, I accidently did so _at_ the particle location.
That was a mousing error. The particle obeys smooth drag, not
snap-to-mouse-location. You can also drag the mouse in the X and Y
controllers, not demonstrated here.
Here are some more detailed specifications:
- The entire system works on a 600 x 500 canvas.
- Hitting one of the following keys causes a new controller to
appear in the center of the canvas:
- "p" : Position controller
- "v" : velocity controller
- "x" : X controller
- "y" : Y controller
- "z" : XY controller
- Each controller has a 10x10 handle. Dragging on the handle
moves the controller around the canvas.
- A button-down inside a controller selects the controller for
input.
- In the position or velocity controller, the arrow keys are used
for input. The arrow keys alter the position or velocity of the
particle in the indicated direction. Each press of an arrow key
alters the appropriate quantity by 5.
- In the X, Y, or XY controller, the mouse drags the particle via
smooth drag. The mouse need not be in the representation of the
particle; it need only be in the controller. However, in such a
drag, the particle must remain strictly inside the wall. If the
particle gets outside the wall, then PerfectBounce.rkt will complain
about a contract violation.
- You must use the WidgetWorks.rkt framework, as you did for Problem Set 10.
- I don't want you spending time on the geometry of the Perfect
Bounce. I've provided a file called PerfectBounce.rkt that calculates this for you.
- You must use inheritance to factor out the common parts of the
various controllers.
- Deliver your solution as a set of files, including
WidgetWorks.rkt and PerfectBounce.rkt, and a file top.rkt that
provides a function
run : PosReal -> Void
GIVEN: a frame rate, in sec/tick
EFFECT: Creates and runs the MVC simulation with the given frame rate.
Last modified: Wed Nov 23 15:43:55 Eastern Standard Time 2016